package com.kangaroo.myhome.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kangaroo.myhome.model.TInspTask;
import com.kangaroo.myhome.model.TInspTaskDetail;
import com.kangaroo.myhome.service.impl.TInspTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.kangaroo.myhome.Exception.CustomException;
import com.kangaroo.myhome.Exception.CustomExceptionType;
import com.kangaroo.myhome.model.TInspProject;
import com.kangaroo.myhome.model.TInspProjectExcel;
import com.kangaroo.myhome.service.impl.TInspProjectService;
import com.kangaroo.myhome.utils.ExcelExport2;
import com.kangaroo.myhome.vo.ResponseModel;

/**
 * @Description: 功能描述: //
 * @author: kangaroo
 * @date: 2020/7/31 0:02
 */
@RestController
@RequestMapping("task")
public class TInspTaskController {

    @Autowired
    private TInspTaskService tInspTaskService;


    // @PreAuthorize("hasAuthority('sys:user:view')")
    @GetMapping(value = "/findAll")
    public ResponseModel findAll(HttpServletRequest request) {
        String name = request.getParameter("name");
        String pageS = request.getParameter("page");
        String rowsS = request.getParameter("rows");
        int page = Integer.parseInt(pageS);
        int rows = Integer.parseInt(rowsS);
        return tInspTaskService.findAll(name, page, rows);
    }

    @GetMapping(value = "/findAllDetail")
    public ResponseModel findAllJson(HttpServletRequest request) {
        String taskId = request.getParameter("taskId");
        String pageS = request.getParameter("page");
        String rowsS = request.getParameter("rows");
        int page = Integer.parseInt(pageS);
        int rows = Integer.parseInt(rowsS);
        return tInspTaskService.findAllDetail(taskId, page, rows);
    }

    // @PreAuthorize("hasAuthority('sys:user:edit')")
    @PostMapping(value = "/edit")
    public ResponseModel edit(@RequestBody TInspTask tInspTask) {
        return tInspTaskService.edit(tInspTask);
    }

    @PostMapping(value = "/editDetail")
    public ResponseModel editInfo(@RequestBody TInspTaskDetail tInspTasDetail) {
        return tInspTaskService.editDetail(tInspTasDetail);
    }



    // @PreAuthorize("hasAuthority('sys:user:delete')")
    @PostMapping(value = "/delete")
    public ResponseModel delete(HttpServletRequest request) {
        String id = request.getParameter("id");
        TInspTask tInspTask = new TInspTask();
        tInspTask.setId(id);
        tInspTaskService.delete(tInspTask);
        ResponseModel model = new ResponseModel();
        model.setCode(200);
        model.setMessage("获取成功");
        return model;
    }

    // @PreAuthorize("hasAuthority('sys:user:delete')")
    @PostMapping(value = "/deleteDetail")
    public ResponseModel deleteDeatail(HttpServletRequest request) {
        String id = request.getParameter("id");
        TInspTaskDetail tInspTask = new TInspTaskDetail();
        tInspTask.setId(id);
        tInspTaskService.deleteDetail(tInspTask);
        ResponseModel model = new ResponseModel();
        model.setCode(200);
        model.setMessage("获取成功");
        return model;
    }



}